﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using DomainDriver.CommonUtilities.Reflectors;
using DomainDriver.DomainModeling.DomainModels;

namespace DomainDriver.DomainModeling.Constraints
{
    public abstract class ConstraintBase : IConstraint
    {
        private IDomainModel m_DomainModel;
        private string m_Name;
        private bool m_Enabled;

        public ConstraintBase(IDomainModel domainModel)
        {
            m_DomainModel = domainModel;
            m_Name = ClassReflector.GetClassNameWithArgs(this.GetType());
            m_Enabled = true;
        }

        public IDomainModel DomainModel
        {
            get { return m_DomainModel; }
        }

        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        public bool Enabled
        {
            get { return m_Enabled; }
            set { m_Enabled = value; }
        }

        public virtual bool RequiresSetup
        {
            get { return false; }
        }

        public virtual void Setup()
        {
            // do nothing
        }

        protected List<PropertyInfo> ExtractConstrainedPropertyInfo<ROOT_OBJECT>(string fullPropertyName)
        {
            if (string.IsNullOrWhiteSpace(fullPropertyName))
            { return null; }

            List<PropertyInfo> nestedPropertyInfos = ClassReflector.GetNestedPropertiesByName(typeof(ROOT_OBJECT), fullPropertyName);
            return nestedPropertyInfos;
        }
    }
}